import React, { memo, useRef } from "react";
import type { ReactNode, FC } from "react";
import axios from "axios";
import { message } from "antd";
interface IProps {
  children?: ReactNode;
}
const Write: FC<IProps> = () => {
  const titleRef = useRef();
  const contentRef = useRef();
  const handleClick = () => {
    axios
      .post("/posts", {
        id: Math.random() * 100000000000,
        username: "zsw",
        title: (titleRef.current as any).value,
        desc: (contentRef.current as any).value,
        replyId: 11,
        replyContent: "reply1"
      })
      .then((res) => {
        if (res.status === 201) {
          message.success("发帖成功！");
        } else {
          message.error("发帖失败");
        }
      });
  };
  return (
    <div>
      <h2>写帖子</h2>
      <input type="text" defaultValue={"标题"} ref={titleRef as any} />
      <textarea defaultValue={"内容"} ref={contentRef as any}></textarea>
      <button onClick={handleClick}>发帖</button>
    </div>
  );
};
export default memo(Write);
